//
// Created by wujehy on 2020/8/3.
//

#include "ListernerManager.h"
#include "Listers/TestOneListerner.h"

void ListernerManager::init()
{
    registerListerners();
}

void ListernerManager::registerListerners()
{
    TestOneListerner *oneListerner = new TestOneListerner;
    auto pt1 = m_Listerner_map.insert( {oneListerner->type(), oneListerner} );
    if (!pt1.second)
    {
        delete oneListerner;
    }


}

ManagerBase::Type ListernerManager::type()
{
    return ManagerType_Listerner;
}

void ListernerManager::callEvent(int type)
{
    auto find = m_Listerner_map.find( type );
    if (find != m_Listerner_map.end())
    {
        find->second->update();
    } else
    {
        // TODO not fount listerner
    }
}

ListernerManager::~ListernerManager()
{
    fprintf( stderr, "delete ListernerManager \n" );

    for (auto lis:m_Listerner_map)
    {
        delete lis.second;
    }
}

ListernerManager::ListernerManager()
{
    fprintf( stderr, "init ListernerManager \n" );

}

void ListernerManager::init_finished()
{
    // 子模块 轮寻 触发
    for (auto lis : m_Listerner_map)
    {
        lis.second->init_finished();
    }
}
